package clockIn

import (
	"clockIn/internal/service"
	"context"
	"github.com/gogf/gf/v2/errors/gcode"
	"github.com/gogf/gf/v2/errors/gerror"

	"clockIn/api/clockIn/v1"
)

func (c *ControllerV1) Create(ctx context.Context, req *v1.CreateReq) (res *v1.CreateRes, err error) {
	status, err := service.ClockIn().Create(ctx, req.ItemId)
	if status == 0 {
		return nil, gerror.New("打卡失败")
	} else if status == 1 {
		// return nil, gerror.NewCode(gcode.New(400, "今日已打卡", nil))
		return nil, gerror.NewOption(gerror.Option{
			Text: "今日已打卡",
			Code: gcode.CodeOperationFailed,
		})
	}
	return
}
